<?php
defined('_JEXEC') or die('Restricted access');
$img_dir = JPATH_SITE.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'fileupload'.DIRECTORY_SEPARATOR;
$img_path = JURI::root(true).'/images/fileupload/';
$title = ($this->id)?"Sửa thông tin mã lỗi":"Thêm mã lỗi mới";
?>
<div class='tab_content' id="tab_create_maloi">
	<div class='container-fluid container_root margin10'>
		<div class='row-fluid'>
			<div class='widget widget-padding span12'>
				<div class='widget-header'>
					<i class="icon-plus"></i>
					<h5><?php echo $title ?></h5>
				</div>
				<div class='widget-body'>
								
					<form class='form' id="form_create_maloi" method="post" enctype="multipart/form-data" action="index.php">
						<div class='row-fluid'>
							<div class='span12'>
								<button type="submit" class='btn btn-primary'>
									<i class='icon-ok icon-white'></i>
									<?php echo JText::_("COM_KETNOI_SAVEBTN") ?>
								</button>
								
								<a type="submit" href="#maloi" class='btn btn-primary'>
									<i class='icon-reorder icon-white'></i>
									Danh sách
								</a>
							</div>
						</div>
						
						<div class="row-fluid margin10">
							<div class='span12'>
								<div class="row-fluid">
									<div class='span6'>
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		<?php echo JText::_("COM_KETNOI_CODE") ?>
												<em>*</em>
											</label>
					                        <div class="controls row-fluid">
					                            <input type='text' value='<?= $this->row->ma ?>' required='required' name='ma' class="span12"/>
					                       		<?php if($this->id): ?>
					                       			<input type='hidden' id='oldma' value='<?= $this->row->ma ?>' /> 
					                       		<?php endif; ?>
					                        </div>
				                        </div>
									</div>
									
									<div class='span6'>
										<div class="control-group">
				                          	<label>
												Tên lỗi
												<em>*</em>
											</label>
					                        <div class="controls row-fluid">
					                            <input value='<?= $this->row->ten ?>' type='text' required='required' name='ten' class="span12"/>
					                        	<?php if($this->id): ?>
					                       			<input type='hidden' id='oldten' value='<?= $this->row->ten ?>' /> 
					                       		<?php endif; ?>
					                        </div>
				                        </div>
									</div>
									
								</div>
																
								<div class="row-fluid">
									<div class='span4'>
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		<?php echo JText::_("COM_KETNOI_GHICHU") ?>
											</label>
					                        <div class="controls row-fluid">
					                        	<textarea name='ghichu' class="span12"><?= $this->row->ghichu ?></textarea>
					                        </div>
				                        </div>
									</div>
									
									<div class='span8'>
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		<?php echo JText::_("COM_KETNOI_HINHANH") ?>
											</label>
					                        <div class="controls row-fluid">
					                        	<div class='browse_button'>
													<a class='btn browse_button' onclick="addmorefile(this,'fileList','file')" id="fileSelect">
														<?php echo JText::_("COM_KETNOI_CHONHINH") ?>
													</a> 
													<div id="fileList">
														<?php $img_list = json_decode($this->row->hinhanh); ?>
														<?php if(count($img_list) > 0 && !empty($img_list)): ?>
														<?php foreach($img_list as $img): ?>
															<?php if(JFile::exists($img_dir.$img)): ?>
																<div>
															  		<img class="img-polaroid" src="<?= $img_path . $img ?>" height="60">
															  		<img style="display: none;" class="img_tmp" src="<?= $img_path . $img ?>" height="60">
															  		<a img_name='<?= $img ?>'>
															  			<i class="icon-remove"></i>
															  		</a>
															  	</div>
															<?php endif; ?>
														<?php endforeach; ?>
														<?php endif; ?>
													  	<input type="hidden" id="delete_file" name="delete_file" value="[]" />
													  	<input type="hidden" name="old_file" value='<?= $this->row->hinhanh ?>' />
													</div>
					                        	</div>
					                        </div>
				                        </div>
									</div>
									 
								</div>
							</div>
						</div>
						
						<input type="hidden" name="option" value="com_ketnoi" />
						<input type="hidden" name="view" value="maloi" />
						<input type="hidden" name="task" value="maloi.save" />
						<input type="hidden" name="layout" value="create" />
						<input type="hidden" name="tmpl" value="raw" />
						<input type="hidden" name="quickcreate" value="<?= JRequest::getVar("quickcreate",0) ?>" />
						<?php if($this->id): ?>
						<input type="hidden" name="id" value="<?= $this->id ?>" />
						<?php endif; ?>
					</form>
				</div>
				
			</div>
		</div>
	</div>
</div>

<script>
	<?php if($this->id): ?>
		setHash("edit_maloi",<?= json_encode(array("id"=>$this->id)) ?>);
	<?php endif; ?>
</script>